import org.springframework.web.bind.annotation.PostMapping;

@PostMapping("/register")
public ModelAndView handleregister(ModelAndView mav, User user) {
    try {
        System.out.println("Registering user: " + user);
        boolean result = userService.register(user);
        System.out.println("Registration result: " + result);
        
        if (!result) {
            mav.addObject("msg", "注册失败，请重试");
            mav.setViewName("register");
            return mav;
        }
        
        // 注册成功的处理
        mav.addObject("msg", "注册成功！");
        mav.setViewName("login");  // 注册成功后跳转到登录页面
        return mav;
        
    } catch (Exception e) {
        e.printStackTrace();
        mav.addObject("msg", "注册发生错误：" + e.getMessage());
        mav.setViewName("register");
    }
    return mav;
} 